#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
User: lyj
DateTime: 2012-05-20 14:01:00

"""

__author__ = 'lyj'



from demos.rabbitmq.settings import amqp_host, amqp_port
import pika


# Synchronous programming style, no concurrency
# 同步程序类型，非并发

# Create our connection parameters and connect to RabbitMQ
parameters = pika.ConnectionParameters(host=amqp_host, port=amqp_port)
connection = pika.BlockingConnection(parameters)

# Open the channel
channel = connection.channel()

# Declare the queue
channel.queue_declare(queue="test", durable=True,
    exclusive=False, auto_delete=False)

# Construct a message and send it
channel.basic_publish(exchange='',
    routing_key="test",
    body="Hello World!",
    properties=pika.BasicProperties(
        content_type="text/plain",
        delivery_mode=1))
print " [x] Sent 'Hello World!'"
connection.close()